<?php

use yii\db\Migration;

/**
 * Handles the creation of table `admin_log`.
 */
class m171128_032422_create_admin_log_table extends Migration
{
    /**
     * @inheritdoc
     */
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%admin_log}}', [
            'id' => $this->primaryKey(),
            'route' => $this->string(255)->notNull()->defaultValue('')->comment('路由'),
            'description' => $this->text()->comment('描述'),
            'user_id' => $this->integer(11)->notNull()->comment('管理员ID'),
            'ip' => $this->string(32)->notNull()->defaultValue('')->comment('登陆IP'),
            'create_at' => $this->integer(11)->notNull()->comment('添加时间')
        ], $tableOptions);
    }

    /**
     * @inheritdoc
     */
    public function down()
    {
        $this->dropTable('{{%admin_log}}');
    }
}
